package com.imooc.activity7_workflow;

import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.ProcessDefinition;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

@SpringBootTest
public class Part2_ProcessDefinition {

    @Autowired
    private RepositoryService repositoryService;

    /**
     * 查询流程定义
     */
    @Test
    public void getDefinitions(){
        List<ProcessDefinition> list = repositoryService.createProcessDefinitionQuery()
                .list();
        list.forEach(processDefinition -> {
            System.out.println("-------------------------流程定义-------------------------");
            System.out.println("Name：" + processDefinition.getName());
            System.out.println("Key：" + processDefinition.getKey());
            System.out.println("ResourceName：" + processDefinition.getResourceName());
            System.out.println("DeploymentId：" + processDefinition.getDeploymentId());
            System.out.println("Version：" + processDefinition.getVersion());
        });
    }

    /**
     * 删除流程定义
     */
    @Test
    public void delDefinitions(){
        String pdId = "4b85d644-4130-11eb-a38b-c23049e74a6b";
        repositoryService.deleteDeployment(pdId, false);
        System.out.println("删除流程定义成功");
    }

}
